package com.yyds.yygh.order.controller.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yyds.yygh.common.result.Result;
import com.yyds.yygh.common.utils.AuthContextHolder;
import com.yyds.yygh.enums.OrderStatusEnum;
import com.yyds.yygh.model.order.OrderInfo;
import com.yyds.yygh.order.service.OrderInfoService;
import com.yyds.yygh.vo.order.OrderCountQueryVo;
import com.yyds.yygh.vo.order.OrderQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Api(tags = "订单接口")
@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderInfoApiController {
    @Autowired
    private OrderInfoService orderInfoService;

    @ApiOperation("创建订单")
    @PostMapping("/auth/submitOrder/{scheduleId}/{patientId}")
    public Result saveOrder(@PathVariable String scheduleId,
                            @PathVariable Long patientId){
        Long order = orderInfoService.saveOrder(scheduleId, patientId);
        return Result.success(order);
    }
    @ApiOperation("根据订单id查询订单详情")
    @GetMapping("/auth/getOrderInfo/{orderId}")
    public Result getOrderInfo(@PathVariable Long orderId){
        OrderInfo orderInfo = orderInfoService.getOrderInfo(orderId);
        return Result.success(orderInfo);
    }
    @ApiOperation("分页查询订单信息")
    @GetMapping("/auth/{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit,
                       OrderQueryVo orderQueryVo, HttpServletRequest request){
        //设置当前用户id
        orderQueryVo.setUserId(AuthContextHolder.getUserId(request));
        Page<OrderInfo> pages = new Page<>(page,limit);
        Page<OrderInfo> orderInfoPage = orderInfoService.selectPage(pages, orderQueryVo);
        return Result.success(orderInfoPage);
    }
    @ApiOperation("获取所有订单状态")
    @GetMapping("/auth/getStatusList")
    public Result getStatusList(){
        List<Map<String, Object>> list = OrderStatusEnum.getStatusList();
        return Result.success(list);
    }
    @ApiOperation(value = "获取订单统计数据")
    @PostMapping("inner/getCountMap")
    public Map<String, Object> getCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo) {
        return orderInfoService.getCountMap(orderCountQueryVo);
    }

}
